package cn.cf319.xg.textapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MainActivity extends AppCompatActivity {

    private ListView        listView;
    private AdapterSaleItem adapterSaleItem;
    Random random = new Random();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        listView = (ListView) findViewById(R.id.listView);


        List<ProductItem> items = new ArrayList<ProductItem>();
        ProductItem item = null;
        for(int i = 0 ;i < 10; i++) {
            item = new ProductItem();
            item.setId(System.currentTimeMillis());
//            item.setImageUrl("images/"+getImages()[random.nextInt(7)]);
            item.setRemainTime(getRandomTime());
            items.add(item);
        }

        System.out.println("items"+items.size());
        adapterSaleItem = new AdapterSaleItem(this, items);
        listView.setAdapter(adapterSaleItem);

    }
    private long getRandomTime() {
        long curTime = System.currentTimeMillis();
        long [] t = new long[] {500,200,640,120,300,450,100,1000,1540,2500};
        return curTime + t[random.nextInt(9)]*1000;
    }
    private String [] getImages() {
        String [] images = null;
        try {
            images = this.getApplicationContext().getAssets().list("images");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return images;
    }


}
